package com.gba.mark.origin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gba.mark.origin.entity.Origin;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface OriginMapper extends BaseMapper<Origin> {



    @Select("SELECT `id` FROM `origin` \n" +
            "WHERE `article_id` =  #{articleId} \n" +
            "AND `opt_lock` = 0 \n" +
            "LIMIT #{needNum}")
    List<Integer> getOriginIdList( @Param("needNum") int needNum, @Param("articleId") Integer articleId);

    @Update("UPDATE `origin`\n " +
            "SET `opt_lock` = 1 \n" +
            "WHERE `id` = #{origin_id}\n")
    void lockOrigin(@Param("origin_id") Integer origin_id);

    @Update("UPDATE `origin` \n" +
            "SET `opt_lock` = 0 \n" +
            "WHERE `id` = #{origin_id}\n")
    void unLockOrigin(@Param("origin_id") int origin_id);

    @Update("UPDATE `origin` \n" +
            "SET `active` = false \n" +
            "WHERE `id` = #{origin_id}\n")
    void updateActive(@Param("origin_id") int origin_id);

}
